/*
 * ChainedComponent.java
 *
 * Created on September 6, 2006, 11:43 AM
 *
 * (C) 2006 R. Alexander Milowski
 */

package com.smallx.xproc.library;

import java.net.URI;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.infoset.component.ComponentDefinition;
import org.infoset.xml.Document;
import org.infoset.xml.Name;

/**
 * A ChainedComponent represents a component that has a primary input
 * bound and all other inputs are statically bound to resources.
 * @author alex
 */
public class ChainedComponent {
   
   Map<Name,Object> staticBindings;
   Name input;
   Name output;
   ComponentDefinition component;
   
   /** Creates a new instance of ChainedComponent */
   public ChainedComponent(Name inputName, Name outputName,ComponentDefinition component) {
      this.staticBindings = null;
      this.input = inputName;
      this.output = outputName;
      this.component = component;
   }
   
   public Name getInputPort() {
      return input;
   }
   
   public Name getOutputPort() {
      return output;
   }
   
   public ComponentDefinition getComponent() {
      return component;
   }
   
   public void addStaticBinding(Name port,URI location)
   {
      if (staticBindings==null) {
         staticBindings = new HashMap<Name,Object>();
      }
      staticBindings.put(port,location);
   }
   
   public void addStaticBinding(Name port,Document doc)
   {
      if (staticBindings==null) {
         staticBindings = new HashMap<Name,Object>();
      }
      staticBindings.put(port,doc);
   }
   
   public Set<Name> getStaticallyBoundPorts() {
      if (staticBindings==null) {
         Set<Name> empty = Collections.emptySet();
         return empty;
      } else {
         return staticBindings.keySet();
      }
   }
   
   public Object getStaticBinding(Name port) {
      return staticBindings==null ? null : staticBindings.get(port);
   }
   
}
